package cn.fl.project.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cn.cmm.base.framework.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.list.AbstractLinkedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cn.fl.project.condition.PrjRskAudWarnRecQC;
import cn.fl.project.service.IPrjRskAudWarnRecService;
import cn.fl.project.vo.PrjRskAudWarnRecVO;
import cn.fl.framework.base.context.CurrentThreadContext;

import cn.fl.system.constant.SysLogConstant;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;

/**
 * @Description: PRJ_RSK_AUD_WARN_REC(项目风险审核提醒表) 控制层
 */
@Controller
@RequestMapping("/project/prjRskAudWarnRec")
public class PrjRskAudWarnRecController extends BaseController {

	/**
	 * PrjRskAudWarnRec 服务层BEAN
	 */
	@Autowired
	private IPrjRskAudWarnRecService prjRskAudWarnRecService;

	@RequestMapping(value = "/searchPrjRskWarnRec.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchPrjRskWarnRec(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		try {
			BaseLogUtils.newLogger("searchPrjRskWarnRec,获取项目风险提醒记录.请求参数,request:{}", JSON.toJSONString(request.getParameterMap())).info();
			String prjId = request.getParameter("prjId");
			String optTyp = request.getParameter("optTyp");
			if (StringUtils.isBlank(prjId)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("项目ID为空");
				return result;
			}
			PrjRskAudWarnRecQC prjRskAudWarnRecQC = new PrjRskAudWarnRecQC();
			prjRskAudWarnRecQC.setPrjId(Long.valueOf(prjId));
			prjRskAudWarnRecQC.setOptTyp(optTyp);
			prjRskAudWarnRecQC.setIsDel(BaseConstant.IS_YESNO_NO);
			BaseLogUtils.newLogger("searchPrjRskWarnRec,获取项目风险提醒记录Start.参数,prjRskAudWarnRecQC:{}", JSON.toJSONString(prjRskAudWarnRecQC)).info();
			List<PrjRskAudWarnRecVO> prjRskAudWarnRecVOList = this.prjRskAudWarnRecService.searchPrjRskWarnRec(prjRskAudWarnRecQC);
			BaseLogUtils.newLogger("searchPrjRskWarnRec,获取项目风险提醒记录End.结果,prjRskAudWarnRecVOList:{}", JSON.toJSONString(prjRskAudWarnRecVOList)).info();
			if (CollectionUtils.isNotEmpty(prjRskAudWarnRecVOList)) {
				ListPageVO<PrjRskAudWarnRecVO> listPage = new ListPageVO<>(prjRskAudWarnRecVOList, prjRskAudWarnRecVOList.size());
				result.setData(listPage);
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.newLogger("searchPrjRskWarnRec,查询失败,异常.DATA:{},ex:{},CurrentUser:{}", JSONObject.toJSONString(request.getParameterMap()), e.getMessage(), CurrentThreadContext.getCurrentUserName()).info();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newLogger("searchPrjRskWarnRec,查询失败,异常.DATA:{},ex:{},CurrentUser:{}", JSONObject.toJSONString(request.getParameterMap()), e.getMessage(), CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		BaseLogUtils.newLogger("searchPrjRskWarnRec,获取项目风险提醒记录.返回结果,result:{}", JSON.toJSONString(result)).info();
		return result;
	}

	@RequestMapping(value = "/toPrjRskAudWarnRecTabPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toPrjRskAudWarnRecTabPage(HttpServletRequest request,HttpServletResponse response) {
		BaseLogUtils.newLogger("跳转项目风险审核记录提醒页,request:{}", JSON.toJSONString(request.getParameterMap())).info();
		String prjId = request.getParameter("prjId");
		String optTyp = request.getParameter("optTyp");
		ModelAndView view = new ModelAndView("/project/prjRskAudWarnRec/prjRskAudWarnRecInfo");
		view.addObject("prjId", prjId);
		view.addObject("optTyp", optTyp);
		BaseLogUtils.newLogger("跳转项目风险审核记录提醒页,view:{}", JSON.toJSONString(view)).info();
		return view;
	}
}

